﻿Imports System.IO
Imports System.Configuration

Public Class Logging
    Public Sub WriteLog(Optional ByVal sAction As String = "", Optional ByVal bWebcontent As Boolean = False)
        'On Error GoTo ErrorHandle
        Dim AppPath As String = ConfigurationManager.AppSettings("LogFile")

        Dim sDay As String = Format(Now(), "dd"), sMonth As String = Format(Now(), "MM")
        Dim strLogFileName As String = sDay & "-" & sMonth & "-" & Year(Now()) & ".log"

        If bWebcontent = False Then
            AppPath &= "\LogFiles\"

            Dim strFolderName As String = AppPath & Year(Now()) & "-" & sMonth
            'T?o thu m?c n?u chua có
            If Not System.IO.Directory.Exists(strFolderName & "\") Then System.IO.Directory.CreateDirectory(strFolderName & "\")
            strLogFileName = strFolderName & "\" & strLogFileName
            System.IO.File.AppendAllText(strLogFileName, Format(Now(), "hh:mm:ss tt") & " : " & sAction & vbCrLf)
        Else
            strLogFileName = AppPath & "\WebContent.txt"
            System.IO.File.WriteAllText(strLogFileName, Format(Now(), "hh:mm:ss tt") & " : " & sAction)
        End If
    End Sub
End Class
